<template>
	<view>
		<Navbar></Navbar>
		
		<Modal :show="modal.show" :confirmText="modal.confirm" :modalContent="modal.content" :showCancel="modal.showCancel"
			@confirm="modalConfirm" @cancel="modal.show = false"></Modal>
	</view>
</template>

<script>
	import Navbar from '@/components/Navbar.vue'
	import Modal from '@/components/Modal.vue'
	import { userLogin } from '@/network/api.js'
	import { activityDaySign } from '@/network/demand.js'
	import { InitScene } from '@/utils/index.js'
	export default{
		components:{
			Navbar,
			Modal
		},
		data(){
			return{
				modal: {
					show: false,
					showCancel: false,
					confirm: '确定',
					content: ''
				},
				sign_id: 0,
				activityId: 0
			}
		},
		onLoad(options){
			this.sign_id = InitScene(options.scene).sign_id
			this.getUserCode(this.sign_id)
		},
		methods:{
			getUserCode(id){
				const _this = this
				uni.login({
					provider: "weixin",
					success(res){
						userLogin({code:res.code}).then(res=>{
							const params = {
								sign_id: id,
								user_id: res.data.userid
							}
							activityDaySign(params).then(res=>{
								_this.modal.content = `${res.msg}`
								_this.modal.confirm = '确定'
								_this.modal.show = true
								_this.activityId = res.data.activity.id
							})
						})
					}
				})
			},
			modalConfirm(){
				uni.redirectTo({
					url: "/pages/activityDetail/activityDetail?id=" + this.activityId
				})
			}
		}
	}
</script>

<style>
</style>